import { Next, Request, Response } from "restify";

/**
 * @deprecated Explicitly call `instance.method.bind(instance)`
 */
export const bindThis = () => {
  return (target: any, methodName: string, descriptor: PropertyDescriptor) => {
    const method = descriptor.value;
    descriptor.value = function (
      req: Request,
      res: Response,
      next: Next
    ): void {
      /* tslint:disable no-invalid-this */
      return method.apply(this, [req, res, next]);
      /* tslint:enable no-invalid-this */
    };
  };
};
